package com.scott.ch300.lambda.ch02;

import org.junit.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author 黄后林
 * @version 1.0
 * @note
 * @date 2022-06-26 13:12:42
 */
public class LambdaTest {


    private List<Student> studentList = Arrays.asList(
            new Student("张无忌",18,180,35000),
            new Student("周芷若",30,182,45000),
            new Student("赵敏",26,185,55000),
            new Student("小昭",24,177,36000),
            new Student("灭绝师太",32,171,13000)
    );


    @Test
    public void salary(){

        System.out.println(salaryOrHeight(studentList, new ScottPredicate<Student>() {

            @Override
            public boolean test(Student student) {
                // 工资大于25000
                return student.getSalary()>25000;
            }
        }));
    }

    @Test
    public void height(){

        System.out.println(salaryOrHeight(studentList, new ScottPredicate<Student>() {

            @Override
            public boolean test(Student student) {
                // 身高大于180
                return student.getHeight()>180;
            }
        }));
    }


    public List<Student> salaryOrHeight(List<Student> list, ScottPredicate scott){
        List<Student> rs = new ArrayList<>();
        for(Student student : list){
            if(scott.test(student)){
                rs.add(student);
            }
        }
        return rs;
    }




}
